package utills;

import common.AppConfig;
import model.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author quan
 * @Description 判断用户是否登录的工具类
 * @Date 2023/7/4 20:28
 */
public class UserUtils {
    public static User checkUserLoginStatus(HttpServletRequest request){
        //先判断req是否为空
        if(request == null){
            return null;
        }
        //否则获取session
        HttpSession session = request.getSession(false);
        //获取用户对象
        User user = (User) session.getAttribute(AppConfig.USER_SESSION_KEY);
        return user;
    }
}
